<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
    余额: <span id="money">123456789</span>
    <input type="button" id="btn" onclick="change()" value="隐藏">
</div>



</body>
<script>
    var sfz = '340113145205200518'
    var fost = sfz.substring(0,4)
    var last = sfz.substring(14)
    var num = sfz.length-9
    for (var i = 0;i<=num;i++){
        fost+='*'
    }
    document.write(fost,last)



    var add = true
    function change() {
        if (add){
            document.getElementById('money').innerText='*********'
            btn.value = '显示'
            add = false
        }else {
            document.getElementById('money').innerText='123456789'
            btn.value = '隐藏'
            add = true
        }
    }

</script>
</html>